//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package elite.core.staffInfo.sub;

import com.wisdge.dataservice.Result;
import elite.core.dataBase.DBMethod;
import elite.core.dataBase.OneDBPara;
import elite.core.dataBase.StateRsObj;
import elite.core.dataBase.changeUpdateConn;
import elite.core.lang.LangRoot;
import elite.core.log.logCls;
import elite.core.log.logIF;
import elite.core.root.*;
import elite.core.staffInfo.OneStaff;
import elite.core.staffInfo.StaffManagerList;
import elite.core.staffInfo.iface.iStaffLoginChk;
import elite.core.staffInfo.other.LoginPara;
import elite.core.staffInfo.other.LoginReturn;
import elite.core.staffInfo.other.OneRole;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class StaffLoginChk1 implements iStaffLoginChk {
    private static final logIF log = logCls.getMe(StaffManagerList.class);

    public StaffLoginChk1() {
    }

    private int CheckMobileFlag(String vNoStr, String mbFlag) {
        if (mbFlag.equals("MB")) {
            return 1;
        } else if (PublicVar.getInstance().getOTConfig().getOneOT("loginMobileDisable").equals("1")) {
            return -1;
        } else if (vNoStr == null) {
            return -1;
        } else {
            int iCount = vNoStr.length();
            if (iCount != 11) {
                log.debug("S:" + StaticMethod.getThreadID() + " No Mobile:" + vNoStr + " Len <> 11");
                return -1;
            } else {
                for(int i = 0; i < iCount; ++i) {
                    String mTmp = vNoStr.substring(i, i + 1);
                    if (mTmp.compareTo("0") < 0 || mTmp.compareTo("9") > 0) {
                        log.debug("S:" + StaticMethod.getThreadID() + " No Mobile:" + vNoStr + " CharIndex:" + i);
                        return -1;
                    }
                }

                return 1;
            }
        }
    }

    private Result getAgentIDByMobile(Connection conn, String vMobile, String vDBExt, String vEPID, String grpId, LogObj logk) {
        String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", vEPID, grpId, logk);
        List<OneDBPara> para = new ArrayList();
        para.add(new OneDBPara(vMobile, 0));
        String mStrSql;
        if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
            mStrSql = "Select AGENT_ID,WORKSTATUS from STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " where MOBILE=? ";
        } else {
            mStrSql = "Select LOGINNAME,WORKSTATUS from STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " where MOBILE=? ";
        }

        StateRsObj rs = DBMethod.getBoundRs(conn, mStrSql, "sql_sys", para, logk);
        if (rs == null) {
            log.info(logk.getLogStr() + " sql do failed:" + mStrSql + " para:" + para.toString());
            return new Result(-3, "AGENTDBERROR ");
        } else {
            Result iFlag = PublicRoot.getInstance().getStaffInfoAndFirstF(rs.getRs());
            Result rt;
            if (iFlag.getCode() == 1) {
                rt = new Result(1, DBMethod.getStrValue(rs.getRs(), 1));
            } else {
                PublicRoot.getInstance().StaffWorkStatus(iFlag, conn, logk);
                rt = iFlag;
            }

            rs.closeMe();
            return rt;
        }
    }

    private String CheckUpdate(Connection readConn, Connection updateConn, String dbType, String dbExtStr, String runKey, String staffId, LogObj logk) {
        String mLoginKey = StaticMethod.getLoginKey(runKey);
        List<OneDBPara> para = new ArrayList();
        para.add(new OneDBPara(StaticMethod.FormatLongToDateString(DBMethod.getDBNow(dbType, readConn, logk)), 2));
        para.add(new OneDBPara(mLoginKey, 0));
        String mSql = "Update WEBLOGINLIST" + dbExtStr.toUpperCase() + "  set CHECKDBTIME=? Where LOGINKEY=? ";
        String mResult;
        if (DBMethod.ExecBoundSql(updateConn, mSql, "sql_sys", para, logk).getCode() > 0) {
            mResult = "T";
        } else {
            log.debug(logk.getLogStr("没有更新到登录记录:" + mSql + " StaffID:" + staffId + " Key:" + runKey));
            mResult = "F";
        }

        log.debug(logk.getLogStr("Login Check Key:" + runKey + " Result:" + mResult));
        return mResult;
    }

    private void CheckStaffInfo(String LangStr, Result returndata, Connection readConn, Connection updateConn, String loginId, String vStaffID, String vDBExt, String vEPID, String vGrpId, String vPwd, String vUID, int vIngorePwd, LogObj logk) {
        LoginReturn mTmp;
        if (vStaffID.equals("######")) {
            returndata.setCode(1);
            mTmp = (LoginReturn)returndata.getValue();
            mTmp.setAgentId("######");
            mTmp.setStaffId("######");
            mTmp.setStaffName("######");
            mTmp.setHeadimg("");
            mTmp.setIsSupervisor(1);
        } else if (vStaffID.equals("##CT##")) {
            returndata.setCode(1);
            mTmp = (LoginReturn)returndata.getValue();
            mTmp.setAgentId("##CT##");
            mTmp.setStaffId("##CT##");
            mTmp.setStaffName("##CT##");
            mTmp.setHeadimg("");
            mTmp.setIsSupervisor(1);
        } else {
            List<OneDBPara> para = new ArrayList();
            para.add(new OneDBPara(vStaffID, 0));
            String mStrSql = "Select AGENT_ID,STAFFNAME,PASSWORD,HEADIMG, ISSUPERVISOR,WRONGPWDCOUNT from STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " where STAFF_ID=? ";
            String mStrSqlUpdate = "Update STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " set WRONGPWDCOUNT=?,WRONGPWDDATE=? where STAFF_ID=? ";
            StateRsObj rs = DBMethod.getBoundRs(readConn, mStrSql, "sql_sys", para, logk);
            int tryPwdTimes = 0;
            boolean mFlag;
            int mIsSuper;
            String mTmpName;
            String mTmpPWD;
            String mTmpAgentId;
            String mHeadImg;
            if (DBMethod.RecNext(rs.getRs())) {
                mTmpAgentId = DBMethod.getStrValue(rs.getRs(), "AGENT_ID");
                mTmpName = DBMethod.getStrValue(rs.getRs(), "STAFFNAME");
                mTmpPWD = DBMethod.getStrValue(rs.getRs(), "PASSWORD");
                mHeadImg = DBMethod.getStrValue(rs.getRs(), "HEADIMG");
                mIsSuper = DBMethod.getIntValue(rs.getRs(), "ISSUPERVISOR");
                tryPwdTimes = DBMethod.getIntValue(rs.getRs(), "WRONGPWDCOUNT");
                mFlag = true;
            } else {
                mTmpName = "";
                mTmpPWD = "";
                mTmpAgentId = "";
                mHeadImg = "";
                mIsSuper = 0;
                mFlag = false;
            }

            log.debug(logk.getLogStr("Img ID:" + mHeadImg));
            rs.closeMe();
            ArrayList paraUp;
            Result rsUp;
            if (PublicVar.getInstance().staffPwdTryTimes != 0) {
                if (tryPwdTimes == PublicVar.getInstance().staffPwdTryTimes) {
                    returndata.setCode(-55);
                    returndata.setMessage(LangRoot.getInstance().getMsg(LangStr, "staff.pwd.chkTimes", "密码认证错误：已经超过最大重试次数：", logk) + PublicVar.getInstance().staffPwdTryTimes);
                    returndata.setValue(vStaffID);
                    ++tryPwdTimes;
                    paraUp = new ArrayList();
                    paraUp.add(new OneDBPara(String.valueOf(tryPwdTimes), 1));
                    paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                    paraUp.add(new OneDBPara(vStaffID, 0));
                    rsUp = DBMethod.ExecBoundSql(updateConn, mStrSqlUpdate, "sql_sys", paraUp, logk);
                    if (rsUp != null) {
                        log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                    } else {
                        log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
                    }

                    return;
                }

                if (tryPwdTimes > PublicVar.getInstance().staffPwdTryTimes) {
                    returndata.setCode(-56);
                    returndata.setMessage(LangRoot.getInstance().getMsg(LangStr, "staff.pwd.chkTimes", "密码认证错误：已经超过最大重试次数：", logk) + PublicVar.getInstance().staffPwdTryTimes);
                    returndata.setValue(vStaffID);
                    ++tryPwdTimes;
                    paraUp = new ArrayList();
                    paraUp.add(new OneDBPara(String.valueOf(tryPwdTimes), 1));
                    paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                    paraUp.add(new OneDBPara(vStaffID, 0));
                    rsUp = DBMethod.ExecBoundSql(updateConn, mStrSqlUpdate, "sql_sys", paraUp, logk);
                    if (rsUp != null) {
                        log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                    } else {
                        log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
                    }

                    return;
                }
            }

            if (!mFlag) {
                returndata.setCode(-5);
                returndata.setMessage(LangRoot.getInstance().getMsg(LangStr, "staff.pwd.chk", "密码认证错误：未找到对应的用户信息", logk));
            } else {
                if (vIngorePwd == 1) {
                    returndata.setCode(1);
                    mTmp = (LoginReturn)returndata.getValue();
                    mTmp.setAgentId(mTmpAgentId);
                    mTmp.setStaffId(vStaffID);
                    mTmp.setStaffName(mTmpName);
                    mTmp.setHeadimg(mHeadImg);
                    mTmp.setIsSupervisor(mIsSuper);
                } else if (StaticMethod.PassWordCheck(loginId, mTmpPWD, vPwd, vUID, readConn, vEPID, vGrpId, logk) > 0) {
                    returndata.setCode(1);
                    mTmp = (LoginReturn)returndata.getValue();
                    mTmp.setAgentId(mTmpAgentId);
                    mTmp.setStaffId(vStaffID);
                    mTmp.setStaffName(mTmpName);
                    mTmp.setHeadimg(mHeadImg);
                    mTmp.setIsSupervisor(mIsSuper);
                     paraUp = new ArrayList();
                    paraUp.add(new OneDBPara("0", 1));
                    paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                    paraUp.add(new OneDBPara(vStaffID, 0));
                     rsUp = DBMethod.ExecBoundSql(updateConn, mStrSqlUpdate, "sql_sys", paraUp, logk);
                    if (rsUp != null) {
                        log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                    } else {
                        log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
                    }
                } else {
                    returndata.setCode(-5);
                    returndata.setMessage(LangRoot.getInstance().getMsg(LangStr, "staff.pwd.chkpwd", "密码认证错误：密码错误 ", logk));
                    ++tryPwdTimes;
                    paraUp = new ArrayList();
                    paraUp.add(new OneDBPara(String.valueOf(tryPwdTimes), 1));
                    paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                    paraUp.add(new OneDBPara(vStaffID, 0));
                    rsUp = DBMethod.ExecBoundSql(updateConn, mStrSqlUpdate, "sql_sys", paraUp, logk);
                    if (rsUp != null) {
                        log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                    } else {
                        log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
                    }
                }
            }

        }
    }

    private String getDefaultGrp(Connection conn, String vDBExt, String vStaff_ID, LogObj logk) {
        List<OneDBPara> para = new ArrayList();
        para.add(new OneDBPara(vStaff_ID, 0));
        String mStrSql = "Select DEFAULTROLEGROUP from STAFF" + StaticMethod.sqlTN(vDBExt).toUpperCase() + "    where STAFF_ID=? ";
        StateRsObj rs = DBMethod.getBoundRs(conn, mStrSql, "sql_sys", para, logk);
        if (rs == null) {
            log.error(logk.getLogStr() + " 取默认组失败 STAFF_ID:" + vStaff_ID);
            return "";
        } else if (DBMethod.RecNext(rs.getRs())) {
            String mTmp = DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP");
            rs.closeMe();
            log.info(logk.getLogStr() + " 取默认组:" + mTmp + " STAFF_ID:" + vStaff_ID);
            return mTmp;
        } else {
            rs.closeMe();
            log.info(logk.getLogStr() + " 取默认组失败  STAFF_ID不存在:" + vStaff_ID);
            return "";
        }
    }

    private void setGroupInfo(Result returndata, Connection conn, String vStaff_ID, String groupId, String vDBExt, LogObj logk) {
        LoginReturn mTmp;
        if (vStaff_ID.equals("######")) {
            mTmp = (LoginReturn)returndata.getValue();
            mTmp.setGroupId("######");
            mTmp.setGroupName("######");
        } else if (vStaff_ID.equals("##CT##")) {
            mTmp = (LoginReturn)returndata.getValue();
            mTmp.setGroupId("##CT##");
            mTmp.setGroupName("##CT##");
        } else {
            if (groupId == null) {
                groupId = this.getDefaultGrp(conn, vDBExt, vStaff_ID, logk);
            } else if (groupId.trim().equals("")) {
                groupId = this.getDefaultGrp(conn, vDBExt, vStaff_ID, logk);
            }

            List<OneDBPara> para = new ArrayList();
            para.add(new OneDBPara(groupId, 0));
            String mStrSql = "select ROLEGROUPDESCRIPTION from ROLEGROUP" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " where ROLEGROUP_ID=? ";
            StateRsObj rs = DBMethod.getBoundRs(conn, mStrSql, "sql_sys", para, logk);
            String mTmpName;
            if (rs == null) {
                mTmpName = "";
            } else {
                mTmpName = rs.getFristOneValue();
                rs.closeMe();
            }

             mTmp = (LoginReturn)returndata.getValue();
            mTmp.setGroupId(groupId);
            mTmp.setGroupName(mTmpName);
        }
    }

    private void setOneStaffRoleList(Result returndata, Connection conn, String vDBExt, String staffId, LogObj logk) {
        LinkedList mResultList;
        LoginReturn mTmp;
        if (staffId.equals("######")) {
            mResultList = new LinkedList();
            mTmp = (LoginReturn)returndata.getValue();
            mTmp.setRoleList(mResultList);
        } else if (staffId.equals("##CT##")) {
            mResultList = new LinkedList();
            mTmp = (LoginReturn)returndata.getValue();
            mTmp.setRoleList(mResultList);
        } else {
            mResultList = new LinkedList();
            List<OneDBPara> para = new ArrayList();
            para.add(new OneDBPara(staffId, 0));
            String mSql = "select A.ROLE_ID,A.ROLENAME,A.STATUS  from ROLE" + StaticMethod.sqlTN(vDBExt).toUpperCase() + " A ,STAFFROLE" + StaticMethod.sqlTN(vDBExt) + " B where A.ROLE_ID=B.ROLE_ID AND B.STAFF_ID=? ";
            StateRsObj rs = DBMethod.getBoundRs(conn, mSql, "sql_sys", para, logk);
            if (rs != null) {
                while(DBMethod.RecNext(rs.getRs())) {
                    if (DBMethod.getIntValue(rs.getRs(), "STATUS") != 0) {
                        mResultList.add(new OneRole(DBMethod.getStrValue(rs.getRs(), "ROLE_ID"), DBMethod.getStrValue(rs.getRs(), "ROLENAME")));
                    }
                }

                rs.closeMe();
            }

             mTmp = (LoginReturn)returndata.getValue();
            mTmp.setRoleList(mResultList);
        }
    }

    private Result getSuccLoginObj(LoginPara inPara, String vGrpId, String runKey, Connection ReadConn, Connection updateConn, String vDBKey, String epName, int epidNum, String staffId, int ingorePwd, int loginNum, String vRemoteIp, LogObj logk) {
        LoginReturn mTmpReturnValue = new LoginReturn();
        mTmpReturnValue.setEpid(inPara.getEpid());
        mTmpReturnValue.setEpName(epName);
        mTmpReturnValue.setEpId_Num(epidNum);
        mTmpReturnValue.setLoginTime(StaticMethod.getNowTimeBySql());
        if (inPara.getStandFlag() == 1) {
            mTmpReturnValue.setRunKey(runKey + "$" + vDBKey);
        } else {
            mTmpReturnValue.setRunKey(runKey + inPara.getEpid());
        }

        mTmpReturnValue.setOrdIndex(loginNum);
        mTmpReturnValue.setLoginName(inPara.getLoginId());
        mTmpReturnValue.setRemoteInfo(inPara.getRemoteInfo());
        Result mReturnData = new Result();
        mReturnData.setValue(mTmpReturnValue);
        this.CheckStaffInfo(inPara.getUseLang(), mReturnData, ReadConn, updateConn, inPara.getLoginId(), staffId, StaticMethod.getExtTB(inPara.getEpid()), inPara.getEpid(), vGrpId, inPara.getPassword(), inPara.getUid(), ingorePwd, logk);
        if (mReturnData.getCode() < 0) {
            return mReturnData;
        } else {
            String mDBType = PublicVar.getInstance().getOneDBPoolType(vDBKey, logk);
            String mResult = this.CheckUpdate(ReadConn, updateConn, mDBType, StaticMethod.getExtTB(inPara.getEpid()), runKey, staffId, logk);
            if (mResult.equals("T")) {
                this.setGroupInfo(mReturnData, ReadConn, staffId, vGrpId, StaticMethod.getExtTB(inPara.getEpid()), logk);
                this.setOneStaffRoleList(mReturnData, ReadConn, StaticMethod.getExtTB(inPara.getEpid()), staffId, logk);
                return mReturnData;
            } else {
                return null;
            }
        }
    }

    public Result CheckCanLogin(String vDBMain, LoginPara inPara, int clientFlag, LogObj logk) {
        DataSource mDs = PublicVar.getInstance().getDB(vDBMain, 1, logk);
        if (mDs == null) {
            log.info(logk.getLogStr("不能获取要登录的数据库:" + vDBMain));
            return new Result(-11, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDBPool", "不能获取要登录的数据库:", logk) + vDBMain);
        } else {
            Connection mConn = DBMethod.getConnectWait(mDs, logk);
            if (mConn == null) {
                log.info(logk.getLogStr("不能获取要登录的数据库连接信息:" + vDBMain));
                return new Result(-12, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDB", "不能获取要登录的数据库连接信息:", logk) + vDBMain);
            } else {
                List<OneDBPara> para = new ArrayList();
                para.add(new OneDBPara(String.valueOf(clientFlag), 1));
                String mStrSql = "select count(*) from ( select distinct STAFF_ID,DBMAINKEYID from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " where CLIENTFLAG=? and STAFF_ID<>'" + "######" + "' and Staff_ID<>'" + "##CT##" + "' ) a where 1=1";
                StateRsObj rs = DBMethod.getBoundRs(mConn, mStrSql, "sql_sys", para, logk);
                if (rs == null) {
                    DBMethod.CloseConnect(mConn, logk);
                    return new Result(-18, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.lincese", "lisence 检查失败", logk));
                } else {
                    int mTmpCount = StaticMethod.StringToInt(rs.getFristOneValue());
                    rs.closeMe();
                    DBMethod.CloseConnect(mConn, logk);
                    return new Result(1, "", mTmpCount);
                }
            }
        }
    }

    private Result CheckSub(Connection readConn, Connection updateConn, StateRsObj rs, String mLoginAgentId, String localIp, String localPort, String remoteIp, String vDBMain, int vIngorePwd, LoginPara inPara, String vDBPool, String vGrpId, String epName, int epidNum, String vRemoteIp, LogObj logk) {
        StringBuffer allToken = new StringBuffer();

        while(DBMethod.RecNext(rs.getRs())) {
            if (DBMethod.getIntValue(rs.getRs(), "CLIENTFLAG") == inPara.getClientFlag()) {
                String mStr = DBMethod.getStrValue(rs.getRs(), "LOGINKEY");
                if (inPara.getStandFlag() == 1) {
                    allToken.append(",").append(mStr + "$" + vDBMain);
                } else {
                    allToken.append(",").append(mStr + inPara.getEpid());
                }

                String mStafff_ID = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                int mLoginNum = DBMethod.getIntValue(rs.getRs(), "LOGNUM");
                if (!DBMethod.getStrValue(rs.getRs(), "LOGINCOMPUTER").equals(inPara.getRemoteInfo())) {
                    String mTmpRead = "重复登录系统 :DBPool" + vDBPool + " Computer:" + DBMethod.getStrValue(rs.getRs(), "LOGINCOMPUTER") + "--" + DBMethod.getStrValue(rs.getRs(), "DEFAULTDBNAME") + " -- " + inPara.toString();

                    while(DBMethod.RecNext(rs.getRs())) {
                        if (DBMethod.getIntValue(rs.getRs(), "CLIENTFLAG") == inPara.getClientFlag()) {
                            mStr = DBMethod.getStrValue(rs.getRs(), "LOGINKEY");
                            if (inPara.getStandFlag() == 1) {
                                allToken.append(",").append(mStr + "$" + vDBMain);
                            } else {
                                allToken.append(",").append(mStr + inPara.getEpid());
                            }
                        }
                    }

                    rs.closeMe();
                    log.debug(logk.getLogStr("IP:" + vRemoteIp + " " + mTmpRead));
                    LoginReturn mTmpReturnValue = new LoginReturn();
                    mTmpReturnValue.setOrdIndex(mLoginNum);
                    Result mReturnData = new Result();
                    mReturnData.setValue(mTmpReturnValue);
                    this.CheckStaffInfo(inPara.getUseLang(), mReturnData, readConn, updateConn, mLoginAgentId, mStafff_ID, StaticMethod.getExtTB(inPara.getEpid()), inPara.getEpid(), vGrpId, inPara.getPassword(), inPara.getUid(), vIngorePwd, logk);
                    if (mReturnData.getCode() < 0) {
                        log.debug(logk.getLogStr("IP:" + vRemoteIp + " 密码错 ," + mTmpRead));
                        return new Result(-7, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.reLogin", "重复登录系统", logk), "");
                    }

                    if (inPara.getStandFlag() == 1) {
                        return new Result(-7, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.reLogin", "重复登录系统", logk), allToken.substring(1));
                    }

                    return new Result(-7, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.reLogin", "重复登录系统", logk), allToken.substring(1));
                }

                if (DBMethod.getStrValue(rs.getRs(), "DEFAULTDBNAME").equalsIgnoreCase(vDBPool)) {
                    rs.closeMe();
                    Result mReturnData = this.getSuccLoginObj(inPara, vGrpId, mStr, readConn, updateConn, vDBMain, epName, epidNum, mStafff_ID, vIngorePwd, mLoginNum, vRemoteIp, logk);
                    if (mReturnData != null && mReturnData.getCode() > 0) {
                        String mDBType = PublicVar.getInstance().getOneDBPoolType(vDBMain, logk).trim().toUpperCase();
                        List<OneDBPara> para2 = new ArrayList();
                        para2.add(new OneDBPara(StaticMethod.FormatLongToDateString(DBMethod.getDBNow(mDBType, readConn, logk)), 2));
                        para2.add(new OneDBPara(localIp, 0));
                        para2.add(new OneDBPara(localPort, 0));
                        para2.add(new OneDBPara(remoteIp, 0));
                        para2.add(new OneDBPara(mStr, 0));
                        String mSql = "Update WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  set CHECKDBTIME=?,SERVERIP=?,SERVERPORT=?,CLIENTIP=? Where LOGINKEY=? ";
                        Result mResult = DBMethod.ExecBoundSql(updateConn, mSql, "sql_sys", para2, logk);
                        if (mResult.getCode() > 0) {
                            LoginReturn mTmpReturnValue = (LoginReturn)mReturnData.getValue();
                            OneStaff mStaffInfo = PublicRoot.getInstance().getStaffInfo(mTmpReturnValue.getRunKey(), logk);
                            log.debug(logk.getLogStr() + " DO SQL ReInsert His:" + mStaffInfo.reInsertHis(updateConn, localIp, localPort, remoteIp, logk));
                        } else {
                            log.info(logk.getLogStr() + " DO SQL　失败:" + mSql + " Key:" + mStr);
                        }
                    }

                    if (mReturnData == null) {
                        log.debug(logk.getLogStr("再次登录    ID:" + mStr + " Result:无登录信息  --" + inPara.toString()));
                        return null;
                    }

                    log.debug(logk.getLogStr("再次登录    ID:" + mStr + " Result:" + mReturnData.getCode() + " -- " + inPara.toString()));
                    return mReturnData;
                }
            }
        }

        return null;
    }

    public Result CheckLoginStaffFormDB(int isStaffId, String localIp, String localPort, String remoteIp, String vDBMain, int vIngorePwd, LoginPara inPara, String vDBPool, String vGrpId, String epName, int epidNum, String vRemoteIp, LogObj logk) {
        DataSource mDs = PublicVar.getInstance().getDB(vDBMain, 1, logk);
        if (mDs == null) {
            log.error(logk.getLogStr("不能获取要登录的数据库:" + vDBMain));
            return new Result(-11, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDBPool", "不能获取要登录的数据库:", logk) + vDBMain);
        } else {
            Connection mConnCur = DBMethod.getConnectWait(mDs, logk);
            if (mConnCur == null) {
                log.error(logk.getLogStr("不能获取要登录的数据库连接信息:" + vDBMain));
                return new Result(-12, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDB", "不能获取要登录的数据库连接信息:", logk) + vDBMain);
            } else {
                List<OneDBPara> para1 = new ArrayList();
                String mStrSql;
                String mLoginAgentID;
                if (isStaffId == 1) {
                    para1.add(new OneDBPara(inPara.getLoginId(), 0));
                    mStrSql = "Select LOGINKEY,LOGINCOMPUTER,CLIENTFLAG,DEFAULTDBNAME,STAFF_ID,LOGNUM,USELANG from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " Where STAFF_ID=? ";
                    mLoginAgentID = "";
                } else {
                    if (this.CheckMobileFlag(inPara.getLoginId(), vRemoteIp) > 0) {
                        Result getStf = this.getAgentIDByMobile(mConnCur, inPara.getLoginId(), StaticMethod.getExtTB(inPara.getEpid()), inPara.getEpid(), vGrpId, logk);
                        if (getStf.getCode() <= 0) {
                            return getStf;
                        }

                        mLoginAgentID = getStf.getMessage();
                        log.debug(logk.getLogStr("Check Old Staff Mobile:" + inPara.getLoginId() + " Agent_ID/loginname:" + mLoginAgentID));
                    } else {
                        mLoginAgentID = inPara.getLoginId();
                    }

                    if (inPara.getLoginId().startsWith("#S#S#")) {
                        para1.add(new OneDBPara(mLoginAgentID, 0));
                        mStrSql = "Select LOGINKEY,LOGINCOMPUTER,CLIENTFLAG,DEFAULTDBNAME,STAFF_ID,LOGNUM,USELANG from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " Where AGENT_ID=? ";
                    } else if (PublicVar.getInstance().getSqlCase() == 1) {
                        para1.add(new OneDBPara(mLoginAgentID.trim(), 0));
                        mStrSql = "Select LOGINKEY,LOGINCOMPUTER,CLIENTFLAG,DEFAULTDBNAME,STAFF_ID,LOGNUM,USELANG from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " Where  AGENT_ID=? ";
                    } else {
                        para1.add(new OneDBPara(mLoginAgentID.trim().toUpperCase(), 0));
                        mStrSql = "Select LOGINKEY,LOGINCOMPUTER,CLIENTFLAG,DEFAULTDBNAME,STAFF_ID,LOGNUM,USELANG from WEBLOGINLIST" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + " Where upper(AGENT_ID)=? ";
                    }
                }

                StateRsObj rsobj = DBMethod.getBoundRs(mConnCur, mStrSql, "sql_sys", para1, logk);
                if (rsobj == null) {
                    log.error(logk.getLogStr("不能获取要登录的表(WebLoginList):" + vDBMain));
                    DBMethod.CloseConnect(mConnCur, logk);
                    return new Result(-1, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.webtb", "不能获取要登录的表(WebLoginList):", logk) + vDBMain);
                } else {
                    changeUpdateConn upDB = new changeUpdateConn(vDBMain, mConnCur, logk);
                    Result rt = this.CheckSub(mConnCur, upDB.getCurConn(), rsobj, mLoginAgentID, localIp, localPort, remoteIp, vDBMain, vIngorePwd, inPara, vDBPool, vGrpId, epName, epidNum, vRemoteIp, logk);
                    rsobj.closeMe();
                    DBMethod.CloseConnect(mConnCur, logk);
                    upDB.CloseDBConn(logk);
                    return rt;
                }
            }
        }
    }

    private Result checkStaffExists(int isStaffId, Connection conn, String loginId, String grpId, String remoteIP, LogObj logk) {
        List<OneDBPara> para = new ArrayList();
        String strsql;
        Result newID;
        if (isStaffId == 1) {
            para.add(new OneDBPara(loginId, 0));
            strsql = "select WORKSTATUS from  STAFF F where F.STAFF_ID=? ";
        } else if (this.CheckMobileFlag(loginId, remoteIP) > 0) {
            para.add(new OneDBPara(loginId.trim(), 0));
            strsql = "select WORKSTATUS from  STAFF F where F.MOBILE=? ";
        } else {
            String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", "", grpId, logk);
            newID = StaffManagerList.autoSelectStaff(conn, mPara, loginId, "", grpId, logk);
            if (PublicVar.getInstance().getSqlCase() == 1) {
                if (newID.getCode() > 0) {
                    para.add(new OneDBPara(newID.getMessage(), 0));
                } else {
                    para.add(new OneDBPara(loginId.trim(), 0));
                }

                if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select WORKSTATUS from  STAFF F where  F.AGENT_ID =? ";
                } else {
                    strsql = "select WORKSTATUS from  STAFF F where  F.LOGINNAME =? ";
                }
            } else {
                if (newID.getCode() > 0) {
                    para.add(new OneDBPara(newID.getMessage().toUpperCase(), 0));
                } else {
                    para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                }

                if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select WORKSTATUS from  STAFF F where   upper(F.AGENT_ID)=? ";
                } else {
                    strsql = "select WORKSTATUS from  STAFF F where  upper(F.LOGINNAME)=? ";
                }
            }
        }

        StateRsObj rs = DBMethod.getBoundRs(conn, strsql, "sql_sys", para, logk);
        if (rs == null) {
            return new Result(-3, "AGENTDBERROR ");
        } else {
            newID = PublicRoot.getInstance().getStaffInfoAndFirstF(rs.getRs());
            Result rt;
            if (newID.getCode() == 1) {
                rt = new Result(1);
            } else {
                PublicRoot.getInstance().StaffWorkStatus(newID, conn, logk);
                rt = newID;
            }

            rs.closeMe();
            return rt;
        }
    }

    private void InsertLastLoginRole(Connection conn, String staffId, String groupId, LogObj logk) {
        DBMethod.ExecSql(conn, "Delete from STAFFLOGINGRPHIS  Where STAFF_ID='" + staffId + "'", "Rpt_System", logk);
        DBMethod.ExecSql(conn, "Insert into STAFFLOGINGRPHIS  ( STAFF_ID,LOGINGROUPID) values ('" + staffId + "','" + groupId + "')", "Rpt_System", logk);
    }

    private Result selectOneGroupID(String langStr, Connection conn, String staffId, String dbExt, LogObj logk) {
        String strsql = "select ROLEGROUP_ID from STAFFROLEGROUP" + dbExt + " where STAFF_ID=?";
        List<OneDBPara> para = new ArrayList();
        para.add(new OneDBPara(staffId, 0));
        StateRsObj rs = DBMethod.getBoundRs(conn, strsql, "sql_sys", para, logk);
        Result rt;
        if (DBMethod.RecNext(rs.getRs())) {
            rt = new Result(1, DBMethod.getStrValue(rs.getRs(), "ROLEGROUP_ID"));
            this.InsertLastLoginRole(conn, staffId, rt.getMessage(), logk);
        } else {
            rt = new Result(-65, LangRoot.getInstance().getMsg(langStr, "staff.pwd.loggrp", "未获取到对应组", logk));
        }

        rs.closeMe();
        return rt;
    }

    private Result getStaff_MGNT_ORG_CODE(Connection conn, String loginId, String dbExt, String remoteIP, LogObj logk) {
        List<OneDBPara> para = new ArrayList();
        String strsql;
        if (loginId.startsWith("#S#S#")) {
            para.add(new OneDBPara(loginId.substring(5), 0));
            strsql = "select STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from STAFF" + dbExt + " F where STAFF_ID=? ";
        } else if (this.CheckMobileFlag(loginId, remoteIP) > 0) {
            para.add(new OneDBPara(loginId.trim(), 0));
            strsql = "select STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where F.MOBILE=? ";
        } else {
            String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", "", "", logk);
            if (PublicVar.getInstance().getSqlCase() == 1) {
                para.add(new OneDBPara(loginId.trim(), 0));
                if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select  STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where  F.AGENT_ID =?  ";
                } else {
                    strsql = "select  STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where  F.LOGINNAME =? ";
                }
            } else {
                para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                    strsql = "select  STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where   upper(F.AGENT_ID)=?  ";
                } else {
                    strsql = "select  STAFF_ID,MGNT_ORG_CODE,WORKSTATUS from  STAFF" + dbExt + " F where  upper(F.LOGINNAME)=? ";
                }
            }
        }

        StateRsObj rs = DBMethod.getBoundRs(conn, strsql, "sql_sys", para, logk);
        if (rs == null) {
            return new Result(-3, "AGENTDBERROR ");
        } else {
            Result rt = new Result(-4, "no Agent");
            String GroupID = "";

            while(DBMethod.RecNext(rs.getRs())) {
                if ("ONLINE".equalsIgnoreCase(DBMethod.getStrValue(rs.getRs(), "WORKSTATUS"))) {
                    GroupID = DBMethod.getStrValue(rs.getRs(), "MGNT_ORG_CODE");
                    rt = new Result(1, GroupID);
                } else if (rt.getCode() != 1) {
                    rt = new Result(-19, DBMethod.getStrValue(rs.getRs(), "WORKSTATUS"));
                }
            }

            rs.closeMe();
            return rt;
        }
    }

    public Result CheckStaffIP(String loginId, String dbExt, String remoteIP, String currentIP, DataSource ds, LogObj logk) {
        if (!loginId.equalsIgnoreCase("##CT##") && !loginId.equalsIgnoreCase("######")) {
            Connection conn = DBMethod.getConnectWait(ds, logk);
            if (conn == null) {
                return new Result(-11, "数据连接获取失败");
            } else {
                Result rs = this.getStaff_MGNT_ORG_CODE(conn, loginId, dbExt, remoteIP, logk);
                DBMethod.CloseConnect(conn, logk);
                return rs.getCode() > 0 ? IPCheck.DBCheckIn(ds, rs.getMessage(), currentIP, logk) : rs;
            }
        } else {
            return new Result(1, "");
        }
    }

    public Result autoSelectGrp(String loginStr, int isStaffId, Connection conn, String loginId, String dbExt, String remoteIP, LogObj logk) {
        if (!loginId.equalsIgnoreCase("##CT##") && !loginId.equalsIgnoreCase("######")) {
            List<OneDBPara> para = new ArrayList();
            String strsql;
            if (isStaffId == 1) {
                para.add(new OneDBPara(loginId, 0));
                strsql = "select STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from STAFF" + dbExt + " F where STAFF_ID=?  ";
            } else if (loginId.startsWith("#S#S#")) {
                para.add(new OneDBPara(loginId.substring(5), 0));
                strsql = "select STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from STAFF" + dbExt + " F where STAFF_ID=?  ";
            } else if (this.CheckMobileFlag(loginId, remoteIP) > 0) {
                para.add(new OneDBPara(loginId.trim(), 0));
                strsql = "select STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where F.MOBILE=?  ";
            } else {
                String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", "", "", logk);
                if (PublicVar.getInstance().getSqlCase() == 1) {
                    para.add(new OneDBPara(loginId.trim(), 0));
                    if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                        strsql = "select  STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where  F.AGENT_ID =?   ";
                    } else {
                        strsql = "select  STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where  F.LOGINNAME =?  ";
                    }
                } else {
                    para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                    if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                        strsql = "select  STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where   upper(F.AGENT_ID)=?  ";
                    } else {
                        strsql = "select  STAFF_ID,DEFAULTROLEGROUP,WORKSTATUS from  STAFF" + dbExt + " F where  upper(F.LOGINNAME)=?   ";
                    }
                }
            }

            StateRsObj rs = DBMethod.getBoundRs(conn, strsql, "sql_sys", para, logk);
            if (rs == null) {
                return new Result(-3, "AGENTDBERROR ");
            } else {
                Result rt = new Result(-4, "no Agent");
                String Staff_ID = "";
                String GroupID = "";

                while(DBMethod.RecNext(rs.getRs())) {
                    if ("ONLINE".equalsIgnoreCase(DBMethod.getStrValue(rs.getRs(), "WORKSTATUS"))) {
                        Staff_ID = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                        GroupID = DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP");
                        rt = new Result(1);
                    } else if (rt.getCode() != 1) {
                        rt = new Result(-19, DBMethod.getStrValue(rs.getRs(), "WORKSTATUS"));
                    }
                }

                rs.closeMe();
                if (rt.getCode() < 0) {
                    return rt;
                } else {
                    strsql = "select LOGINGROUPID from STAFFLOGINGRPHIS" + dbExt + " where STAFF_ID=?";
                    para = new ArrayList();
                    para.add(new OneDBPara(Staff_ID, 0));
                    rs = DBMethod.getBoundRs(conn, strsql, "sql_sys", para, logk);
                    if (rs == null) {
                        log.error(logk.getLogStr() + "话务员历史登录组表查询失败,sql:" + strsql);
                        return new Result(-66, LangRoot.getInstance().getMsg(loginStr, "staff.pwd.his", "话务员历史登录组表查询失败", logk));
                    } else {
                        if (DBMethod.RecNext(rs.getRs())) {
                            rt = new Result(1, DBMethod.getStrValue(rs.getRs(), "LOGINGROUPID"));
                            rs.closeMe();
                        } else {
                            rs.closeMe();
                            if ("".equals(GroupID.trim())) {
                                rt = this.selectOneGroupID(loginStr, conn, Staff_ID, dbExt, logk);
                            } else {
                                rt = new Result(1, GroupID);
                            }
                        }

                        return rt;
                    }
                }
            }
        } else {
            return new Result(1, "");
        }
    }

    public Result checkStaffHasGrpId(String langStr, int isStaffId, Connection conn, String loginId, String grpId, String remoteIP, LogObj logk) {
        if (!loginId.equalsIgnoreCase("##CT##") && !loginId.equalsIgnoreCase("######")) {
            if (loginId.startsWith("#S#S#")) {
                return new Result(1);
            } else {
                Result rsFF = this.checkStaffExists(isStaffId, conn, loginId, grpId, remoteIP, logk);
                if (rsFF.getCode() < 0) {
                    return rsFF;
                } else {
                    List<OneDBPara> para = new ArrayList();
                    if (isStaffId == 1) {
                        return new Result(1);
                    } else {
                        String strsql;
                        Result iFlag;
                        if (this.CheckMobileFlag(loginId, remoteIP) > 0) {
                            para.add(new OneDBPara(grpId, 0));
                            para.add(new OneDBPara(loginId.trim(), 0));
                            strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID   And S.ROLEGROUP_ID=? and F.MOBILE=? ";
                        } else {
                            String mPara = DBMethod.getParametersSqlEPID(conn, "LOGNAM", "", grpId, logk);
                            iFlag = StaffManagerList.autoSelectStaff(conn, mPara, loginId, "", grpId, logk);
                            if (PublicVar.getInstance().getSqlCase() == 1) {
                                if (iFlag.getCode() > 0) {
                                    para.add(new OneDBPara(grpId, 0));
                                    para.add(new OneDBPara(iFlag.getMessage(), 0));
                                } else {
                                    para.add(new OneDBPara(grpId, 0));
                                    para.add(new OneDBPara(loginId.trim(), 0));
                                }

                                if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                                    strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID  And S.ROLEGROUP_ID=? and F.AGENT_ID =? ";
                                } else {
                                    strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID  And  S.ROLEGROUP_ID=? and  F.LOGINNAME =? ";
                                }
                            } else {
                                if (iFlag.getCode() > 0) {
                                    para.add(new OneDBPara(grpId, 0));
                                    para.add(new OneDBPara(iFlag.getMessage().toUpperCase(), 0));
                                } else {
                                    para.add(new OneDBPara(grpId, 0));
                                    para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                                }

                                if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                                    strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID  And S.ROLEGROUP_ID=? and upper(F.AGENT_ID)=? ";
                                } else {
                                    strsql = "select F.WORKSTATUS from STAFFROLEGROUP S,ROLEGROUP R,STAFF F where F.STAFF_ID=S.STAFF_ID and S.ROLEGROUP_ID=R.ROLEGROUP_ID  And  S.ROLEGROUP_ID=? and upper(F.LOGINNAME)=? ";
                                }
                            }
                        }

                        StateRsObj rs = DBMethod.getBoundRs(conn, strsql, "sql_sys", para, logk);
                        if (rs == null) {
                            return new Result(-23, LangRoot.getInstance().getMsg(langStr, "staff.pwd.grpInfo", "检查登录组信息失败", logk));
                        } else {
                            iFlag = PublicRoot.getInstance().getStaffInfoAndFirstF(rs.getRs());
                            Result rt;
                            if (iFlag.getCode() == 1) {
                                rt = new Result(1);
                            } else {
                                PublicRoot.getInstance().StaffWorkStatus(iFlag, conn, logk);
                                rt = iFlag;
                            }

                            rs.closeMe();
                            return rt;
                        }
                    }
                }
            }
        } else {
            return new Result(1);
        }
    }

    private Result loginRtData(Connection readConn, Connection updateConn, String updateSql, LoginPara inPara, StateRsObj rs, String grpId, String epName, int epidNum, LogObj logk) {
        Result mReturnData = new Result();
        mReturnData.setCode(1);
        LoginReturn mTmpReturnValue = new LoginReturn();
        mReturnData.setValue(mTmpReturnValue);
        mTmpReturnValue.setEpid(inPara.getEpid());
        mTmpReturnValue.setEpName(epName);
        mTmpReturnValue.setEpId_Num(epidNum);
        mTmpReturnValue.setLoginName(inPara.getLoginId());
        mTmpReturnValue.setRemoteInfo(inPara.getRemoteInfo());
        mTmpReturnValue.setStaffId(DBMethod.getStrValue(rs.getRs(), "STAFF_ID"));
        mTmpReturnValue.setStaffName(DBMethod.getStrValue(rs.getRs(), "STAFFNAME"));
        mTmpReturnValue.setAgentId(DBMethod.getStrValue(rs.getRs(), "AGENT_ID"));
        mTmpReturnValue.setHeadimg(DBMethod.getStrValue(rs.getRs(), "HEADIMG"));
        mTmpReturnValue.setIsSupervisor(DBMethod.getIntValue(rs.getRs(), "ISSUPERVISOR"));
        mTmpReturnValue.setLoginTime(StaticMethod.getNowTimeString());
        if (grpId == null) {
            mTmpReturnValue.setGroupId(DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP"));
            log.debug(logk.getLogStr() + " Login Staff Get DefaultGroup:" + mTmpReturnValue.getGroupId() + " Input Group is null");
        } else if (grpId.trim().equals("")) {
            mTmpReturnValue.setGroupId(DBMethod.getStrValue(rs.getRs(), "DEFAULTROLEGROUP"));
            log.debug(logk.getLogStr() + " Login Staff Get DefaultGroup:" + mTmpReturnValue.getGroupId() + " Input Group is Empty");
        } else {
            mTmpReturnValue.setGroupId(grpId);
        }

        rs.closeMe();
        this.setGroupInfo(mReturnData, readConn, mTmpReturnValue.getStaffId(), mTmpReturnValue.getGroupId(), StaticMethod.getExtTB(inPara.getEpid()), logk);
        this.setOneStaffRoleList(mReturnData, readConn, StaticMethod.getExtTB(inPara.getEpid()), mTmpReturnValue.getStaffId(), logk);
        List<OneDBPara> paraUp = new ArrayList();
        paraUp.add(new OneDBPara("0", 1));
        paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
        if (PublicVar.getInstance().getSqlCase() == 1) {
            paraUp.add(new OneDBPara(inPara.getLoginId().trim(), 0));
        } else {
            paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
        }

        if (updateSql.length() > 0) {
            Result rsUp = DBMethod.ExecBoundSql(updateConn, updateSql, "sql_sys", paraUp, logk);
            if (rsUp != null) {
                log.debug(logk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
            } else {
                log.debug(logk.getLogStr() + " Update TryTimes Result is Null");
            }
        }

        return mReturnData;
    }

    private Result loginOneSubStaff(int isStaffId, Connection readConn, Connection updateConn, String vDBMain, int vIngorePwd, LoginPara inPara, String vGrpId, String epName, int epidNum, String vRemoteIp, LogObj mLogk) {
        int empty = -1;
        int dateExprie = -1;
        String mMinLevel = DBMethod.getParametersSqlEPID(readConn, "PWDRUL", inPara.getEpid(), vGrpId, mLogk);
        if (!mMinLevel.trim().equals("")) {
            List<String> arr = StaticMethod.stringToArr(mMinLevel, ",");
            if (arr.size() > 2) {
                empty = StaticMethod.StringToInt((String)arr.get(2));
            }

            if (arr.size() > 3) {
                dateExprie = StaticMethod.StringToInt((String)arr.get(3));
            }
        }

        try {
            List<OneDBPara> para = new ArrayList();
            String mUpdateSql;
            String mStrSql;
            StateRsObj rs;
            if (isStaffId == 1) {
                para.add(new OneDBPara(inPara.getLoginId(), 0));
                mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  S.STAFF_ID=? ";
                mUpdateSql = "";
                log.info(mLogk.getLogStr("Login Info Sql:" + mStrSql + " Para:" + para.toString() + "  " + inPara.toString()));
                rs = DBMethod.getBoundRs(readConn, mStrSql, "sql_sys", para, mLogk);
                if (rs == null) {
                    log.debug(mLogk.getLogStr(" Sql:" + mStrSql + " :AGENTDBERROR " + inPara.toString()));
                    return new Result(-3, "AGENTDBERROR ");
                } else if (DBMethod.RecNext(rs.getRs())) {
                    return this.loginRtData(readConn, updateConn, mUpdateSql, inPara, rs, vGrpId, epName, epidNum, mLogk);
                } else {
                    rs.closeMe();
                    return new Result(-3, "StaffId 不存在 ");
                }
            } else {
                Result newID;
                if (inPara.getLoginId().startsWith("#S#S#")) {
                    para.add(new OneDBPara(inPara.getLoginId().substring(5), 0));
                    mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  S.EWU_ID=? ";
                    mUpdateSql = "";
                } else if (this.CheckMobileFlag(inPara.getLoginId(), vRemoteIp) > 0) {
                    para.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                    mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  S.MOBILE=? ";
                    mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And MOBILE=? ";
                } else {
                    String mPara = DBMethod.getParametersSqlEPID(readConn, "LOGNAM", inPara.getEpid(), vGrpId, mLogk);
                    newID = StaffManagerList.autoSelectStaff(readConn, mPara, inPara.getLoginId().trim(), inPara.getEpid(), vGrpId, mLogk);
                    if (PublicVar.getInstance().getSqlCase() == 1) {
                        if (newID.getCode() > 0) {
                            para.add(new OneDBPara(newID.getMessage(), 0));
                            inPara.setLoginId(newID.getMessage());
                        } else {
                            para.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                        }

                        if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                            mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where S.AGENT_ID=? ";
                            mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And AGENT_ID=? ";
                        } else {
                            mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  S.LOGINNAME =? ";
                            mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And  LOGINNAME =? ";
                        }
                    } else {
                        if (newID.getCode() > 0) {
                            para.add(new OneDBPara(newID.getMessage().toUpperCase(), 0));
                            inPara.setLoginId(newID.getMessage());
                        } else {
                            para.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                        }

                        if (StaticMethod.StringToInt(mPara) != 1 && !mPara.trim().equalsIgnoreCase("Y")) {
                            mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  upper(S.AGENT_ID)=? ";
                            mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And upper(AGENT_ID)=? ";
                        } else {
                            mStrSql = "Select PASSWORD,STAFFNAME,STAFF_ID,AGENT_ID,DEFAULTROLEGROUP,HEADIMG,ISSUPERVISOR,PWDMODIFY,WRONGPWDCOUNT,WORKSTATUS from STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "  S Where  upper(S.LOGINNAME)=? ";
                            mUpdateSql = "update STAFF" + StaticMethod.getExtTB(inPara.getEpid()).toUpperCase() + "   Set WRONGPWDCOUNT=?,WRONGPWDDATE=? Where WORKSTATUS='ONLINE'  And upper(LOGINNAME)=? ";
                        }
                    }
                }

                log.info(mLogk.getLogStr("Login Info Sql:" + mStrSql + " Para:" + para.toString() + "  " + inPara.toString()));
                rs = DBMethod.getBoundRs(readConn, mStrSql, "sql_sys", para, mLogk);
                if (rs == null) {
                    log.debug(mLogk.getLogStr(" Sql:" + mStrSql + " :AGENTDBERROR " + inPara.toString()));
                    return new Result(-3, "AGENTDBERROR ");
                } else {
                    newID = PublicRoot.getInstance().getStaffInfoAndFirstF(rs.getRs());
                    if (newID.getCode() == 1) {
                        int pwdTryTimes = DBMethod.getIntValue(rs.getRs(), "WRONGPWDCOUNT");
                        if (PublicVar.getInstance().staffPwdTryTimes != 0) {
                            String outStaffId;
                            ArrayList paraUp;
                            Result rsUp;
                            if (pwdTryTimes == PublicVar.getInstance().staffPwdTryTimes) {
                                log.debug(mLogk.getLogStr("密码认证错误：已经超过最大重试次数：" + PublicVar.getInstance().staffPwdTryTimes));
                                outStaffId = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                                rs.closeMe();
                                ++pwdTryTimes;
                                paraUp = new ArrayList();
                                paraUp.add(new OneDBPara(String.valueOf(pwdTryTimes), 1));
                                paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                                if (PublicVar.getInstance().getSqlCase() == 1) {
                                    paraUp.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                                } else {
                                    paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                                }

                                if (mUpdateSql.length() > 0) {
                                    rsUp = DBMethod.ExecBoundSql(updateConn, mUpdateSql, "sql_sys", paraUp, mLogk);
                                    if (rsUp != null) {
                                        log.debug(mLogk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                                    } else {
                                        log.debug(mLogk.getLogStr() + " Update TryTimes Result is Null");
                                    }
                                }

                                return new Result(-55, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.chkTimes", "密码认证错误：已经超过最大重试次数：", mLogk) + PublicVar.getInstance().staffPwdTryTimes, outStaffId);
                            }

                            if (pwdTryTimes > PublicVar.getInstance().staffPwdTryTimes) {
                                log.debug(mLogk.getLogStr("密码认证错误：已经超过最大重试次数：" + PublicVar.getInstance().staffPwdTryTimes));
                                outStaffId = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                                rs.closeMe();
                                ++pwdTryTimes;
                                paraUp = new ArrayList();
                                paraUp.add(new OneDBPara(String.valueOf(pwdTryTimes), 1));
                                paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                                if (PublicVar.getInstance().getSqlCase() == 1) {
                                    paraUp.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                                } else {
                                    paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                                }

                                if (mUpdateSql.length() > 0) {
                                    rsUp = DBMethod.ExecBoundSql(updateConn, mUpdateSql, "sql_sys", paraUp, mLogk);
                                    if (rsUp != null) {
                                        log.debug(mLogk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                                    } else {
                                        log.debug(mLogk.getLogStr() + " Update TryTimes Result is Null");
                                    }
                                }

                                return new Result(-56, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.chkTimes", "密码认证错误：已经超过最大重试次数：", mLogk) + PublicVar.getInstance().staffPwdTryTimes, outStaffId);
                            }
                        }

                        if (empty == 1 && DBMethod.getStrValue(rs.getRs(), "PASSWORD").equals("")) {
                            log.debug(mLogk.getLogStr("密码不能为空 :" + vDBMain));
                            rs.closeMe();
                            return new Result(-101, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.isEmpty", "密码不能为空:", mLogk) + vDBMain);
                        } else if (StaticMethod.PassWordCheck(inPara.getLoginId(), DBMethod.getStrValue(rs.getRs(), "PASSWORD"), inPara.getPassword(), inPara.getUid(), readConn, inPara.getEpid(), vGrpId, mLogk) <= 0 && vIngorePwd != 1) {
                            rs.closeMe();
                            log.debug(mStrSql + " :密码错误" + inPara.toString());
                            ++pwdTryTimes;
                            List<OneDBPara> paraUp = new ArrayList();
                            paraUp.add(new OneDBPara(String.valueOf(pwdTryTimes), 1));
                            paraUp.add(new OneDBPara(StaticMethod.getNowTimeBySql(), 2));
                            if (PublicVar.getInstance().getSqlCase() == 1) {
                                paraUp.add(new OneDBPara(inPara.getLoginId().trim(), 0));
                            } else {
                                paraUp.add(new OneDBPara(inPara.getLoginId().trim().toUpperCase(), 0));
                            }

                            if (mUpdateSql.length() > 0) {
                                Result rsUp = DBMethod.ExecBoundSql(updateConn, mUpdateSql, "sql_sys", paraUp, mLogk);
                                if (rsUp != null) {
                                    log.debug(mLogk.getLogStr() + " Update TryTimes Result:" + rsUp.toString());
                                } else {
                                    log.debug(mLogk.getLogStr() + " Update TryTimes Result is Null");
                                }
                            }

                            return new Result(-5, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.err", "密码错误 ", mLogk));
                        } else {
                            if (dateExprie > 0 && vIngorePwd != 1) {
                                Date mModifyDate = DBMethod.getStrDate(rs.getRs(), "PWDMODIFY");
                                if (mModifyDate == null) {
                                    log.debug(mLogk.getLogStr("密码过期，密码无修改时间"));
                                    rs.closeMe();
                                    return new Result(-103, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.expire", "密码过期，密码无修改时间", mLogk));
                                }

                                Date mNow = new Date(System.currentTimeMillis());
                                long day = (mNow.getTime() - mModifyDate.getTime()) / 86400000L;
                                if (day > (long)dateExprie) {
                                    log.debug(mLogk.getLogStr("密码过期，密码已经" + day + " 天未修改"));
                                    rs.closeMe();
                                    return new Result(-102, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.change1", "密码过期，密码已经", mLogk) + day + LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.change2", " 天未修改", mLogk));
                                }
                            }

                            return this.loginRtData(readConn, updateConn, mUpdateSql, inPara, rs, vGrpId, epName, epidNum, mLogk);
                        }
                    } else {
                        log.debug(mStrSql + " :NOAGENT Or Not ONLINE " + inPara.toString() + " RS:" + newID.toString());
                        rs.closeMe();
                        PublicRoot.getInstance().StaffWorkStatus(newID, readConn, mLogk);
                        return newID;
                    }
                }
            }
        } catch (Error var25) {
            log.error(mLogk.getLogStr() + " StaffLogin Check Connect Failed 1", var25);
            return new Result(-6, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.error", "异常错误  ", mLogk));
        } catch (Exception var26) {
            log.error(mLogk.getLogStr() + " StaffLogin Check Connect Failed 2 ", var26);
            return new Result(-6, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.error", "异常错误  ", mLogk));
        }
    }

    public Result LoginOneStaff(int isStaffId, String vDBMain, int vIngorePwd, LoginPara inPara, String vGrpId, String epName, int epIdNum, String vRemoteIp, LogObj mLogk) {
        changeUpdateConn mDB = new changeUpdateConn(vDBMain, mLogk);
        if (mDB.getNewConnFlag() < 0) {
            log.info(mLogk.getLogStr("不能获取要登录的数据库:" + vDBMain));
            return new Result(-11, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.genDBPool", "不能获取要登录的数据库:", mLogk) + vDBMain);
        } else {
            Result rt;
            try {
                rt = this.loginOneSubStaff(isStaffId, mDB.getReadConn(), mDB.getCurConn(), vDBMain, vIngorePwd, inPara, vGrpId, epName, epIdNum, vRemoteIp, mLogk);
            } catch (Error var17) {
                log.info(mLogk.getLogStr() + " 登录异常:" + var17.toString());
                rt = new Result(-1, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.loginerr", "登录异常", mLogk) + var17.toString());
            } catch (Exception var18) {
                log.info(mLogk.getLogStr() + " 登录异常:" + var18.toString());
                rt = new Result(-1, LangRoot.getInstance().getMsg(inPara.getUseLang(), "staff.pwd.loginerr", "登录异常", mLogk) + var18.toString());
            } finally {
                mDB.CloseDBConn(mLogk);
            }

            return rt;
        }
    }

    public Result Logoutstaff(String langStr, String vDBMain, String vTBExtStr, String vEPID, String grpId, String loginId, String password, String vUID, String vRemoteIp, LogObj mLogk) {
        if (loginId.equals("######")) {
            return password.equals(PublicVar.getInstance().getDefaultStaffPwd()) ? new Result(1) : new Result(-1, "用户密码错误");
        } else if (loginId.equals("##CT##")) {
            return password.equals(PublicVar.getInstance().getDefaultCustPwd()) ? new Result(1) : new Result(-1, "用户密码错误");
        } else {
            DataSource mDS = PublicVar.getInstance().getDB(vDBMain, 1, mLogk);
            if (mDS == null) {
                log.info(mLogk.getLogStr() + " 不能获取要登录的数据库:" + vDBMain);
                return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.genDBPool", "不能获取要登录的数据库:", mLogk) + vDBMain);
            } else {
                Connection mConn = DBMethod.getConnectWait(mDS, mLogk);
                if (mConn == null) {
                    log.info(mLogk.getLogStr() + " 不能获取要登录的数据库连接:" + vDBMain);
                    return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.genDB", "不能获取要登录的数据连接:", mLogk) + vDBMain);
                } else {
                    try {
                        List<OneDBPara> para = new ArrayList();
                        String mStrSql;
                        String mStaff_ID;
                        if (this.CheckMobileFlag(loginId, vRemoteIp) > 0) {
                            para.add(new OneDBPara(loginId.trim(), 0));
                            mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "  Where WORKSTATUS='ONLINE' And MOBILE=? ";
                        } else {
                            mStaff_ID = DBMethod.getParametersSqlEPID(mConn, "LOGNAM", vEPID, grpId, mLogk);
                            Result newID = StaffManagerList.autoSelectStaff(mConn, mStaff_ID, loginId, vEPID, grpId, mLogk);
                            if (PublicVar.getInstance().getSqlCase() == 1) {
                                if (newID.getCode() > 0) {
                                    para = new ArrayList();
                                    para.add(new OneDBPara(newID.getMessage(), 0));
                                    loginId = newID.getMessage();
                                } else {
                                    para.add(new OneDBPara(loginId.trim(), 0));
                                }

                                if (StaticMethod.StringToInt(mStaff_ID) != 1 && !mStaff_ID.trim().equalsIgnoreCase("Y")) {
                                    mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "  Where WORKSTATUS='ONLINE' And  AGENT_ID =? ";
                                } else {
                                    mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "   Where WORKSTATUS='ONLINE' And  LOGINNAME =? ";
                                }
                            } else {
                                if (newID.getCode() > 0) {
                                    para = new ArrayList();
                                    para.add(new OneDBPara(newID.getMessage().toUpperCase(), 0));
                                    loginId = newID.getMessage();
                                } else {
                                    para.add(new OneDBPara(loginId.trim().toUpperCase(), 0));
                                }

                                if (StaticMethod.StringToInt(mStaff_ID) != 1 && !mStaff_ID.trim().equalsIgnoreCase("Y")) {
                                    mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "  Where WORKSTATUS='ONLINE' And upper(AGENT_ID)=? ";
                                } else {
                                    mStrSql = "Select PASSWORD,STAFF_ID from STAFF" + StaticMethod.sqlTN(vTBExtStr).toUpperCase() + "   Where WORKSTATUS='ONLINE' And upper(LOGINNAME)=? ";
                                }
                            }
                        }

                        String mTmpPwd = "";
                        StateRsObj rs = DBMethod.getBoundRs(mConn, mStrSql, "sql_sys", para, mLogk);
                        if (rs == null) {
                            mStaff_ID = "";
                        } else if (!DBMethod.RecNext(rs.getRs())) {
                            mStaff_ID = "";
                        } else {
                            mStaff_ID = DBMethod.getStrValue(rs.getRs(), "STAFF_ID");
                            mTmpPwd = DBMethod.getStrValue(rs.getRs(), "PASSWORD");
                        }

                        rs.closeMe();
                        if (!mStaff_ID.equals("")) {
                            if (StaticMethod.PassWordCheck(loginId, mTmpPwd, password, vUID, mConn, vEPID, grpId, mLogk) > 0) {
                                DBMethod.CloseConnect(mConn, mLogk);
                                return new Result(1, mStaff_ID);
                            } else {
                                log.debug(mLogk.getLogStr() + " 用户密码错误");
                                DBMethod.CloseConnect(mConn, mLogk);
                                return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.usepwd", "用户密码错误", mLogk));
                            }
                        } else {
                            DBMethod.CloseConnect(mConn, mLogk);
                            log.debug(mLogk.getLogStr() + " 登出的用户未找到：" + mStrSql);
                            return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.usernf", "用户未找到", mLogk));
                        }
                    } catch (Exception var18) {
                        log.error("PublicClassData Connection Failed", var18);
                        DBMethod.CloseConnect(mConn, mLogk);
                        return new Result(-1, LangRoot.getInstance().getMsg(langStr, "staff.pwd.userout", "登出异常错误 ", mLogk));
                    }
                }
            }
        }
    }
}
